home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume23 / flex2.3 / part06 < prev    next >
Encoding:
Internet Message Format  |  1990-10-10  |  54.1 KB

  1. Subject:  v23i042:  Flex, a fast lex replacement, Part06/10
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: f7ee48d4 ec1d177f 9437dcc3 44a4eec2
  5.  
  6. Submitted-by: Vern Paxson <vern@cs.cornell.edu>
  7. Posting-number: Volume 23, Issue 42
  8. Archive-name: flex2.3/part06
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # Contents:  dfa.c flex.skel yylex.c
  17. # Wrapped by rsalz@litchi.bbn.com on Wed Oct 10 13:24:02 1990
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. echo If this archive is complete, you will see the following message:
  20. echo '          "shar: End of archive 6 (of 10)."'
  21. if test -f 'dfa.c' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'dfa.c'\"
  23. else
  24.   echo shar: Extracting \"'dfa.c'\" \(26919 characters\)
  25.   sed "s/^X//" >'dfa.c' <<'END_OF_FILE'
  26. X/* dfa - DFA construction routines */
  27. X
  28. X/*-
  29. X * Copyright (c) 1990 The Regents of the University of California.
  30. X * All rights reserved.
  31. X *
  32. X * This code is derived from software contributed to Berkeley by
  33. X * Vern Paxson.
  34. X * 
  35. X * The United States Government has rights in this work pursuant
  36. X * to contract no. DE-AC03-76SF00098 between the United States
  37. X * Department of Energy and the University of California.
  38. X *
  39. X * Redistribution and use in source and binary forms are permitted provided
  40. X * that: (1) source distributions retain this entire copyright notice and
  41. X * comment, and (2) distributions including binaries display the following
  42. X * acknowledgement:  ``This product includes software developed by the
  43. X * University of California, Berkeley and its contributors'' in the
  44. X * documentation or other materials provided with the distribution and in
  45. X * all advertising materials mentioning features or use of this software.
  46. X * Neither the name of the University nor the names of its contributors may
  47. X * be used to endorse or promote products derived from this software without
  48. X * specific prior written permission.
  49. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  50. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  51. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  52. X */
  53. X
  54. X#ifndef lint
  55. Xstatic char rcsid[] =
  56. X    "@(#) $Header: /usr/fsys/odin/a/vern/flex/RCS/dfa.c,v 2.7 90/06/27 23:48:15 vern Exp $ (LBL)";
  57. X#endif
  58. X
  59. X#include "flexdef.h"
  60. X
  61. X
  62. X/* declare functions that have forward references */
  63. X
  64. Xvoid dump_associated_rules PROTO((FILE*, int));
  65. Xvoid dump_transitions PROTO((FILE*, int[]));
  66. Xvoid sympartition PROTO((int[], int, int[], int[]));
  67. Xint symfollowset PROTO((int[], int, int, int[]));
  68. X
  69. X
  70. X/* check_for_backtracking - check a DFA state for backtracking
  71. X *
  72. X * synopsis
  73. X *     int ds, state[numecs];
  74. X *     check_for_backtracking( ds, state );
  75. X *
  76. X * ds is the number of the state to check and state[] is its out-transitions,
  77. X * indexed by equivalence class, and state_rules[] is the set of rules
  78. X * associated with this state
  79. X */
  80. X
  81. Xvoid check_for_backtracking( ds, state )
  82. Xint ds;
  83. Xint state[];
  84. X
  85. X    {
  86. X    if ( (reject && ! dfaacc[ds].dfaacc_set) || ! dfaacc[ds].dfaacc_state )
  87. X    { /* state is non-accepting */
  88. X    ++num_backtracking;
  89. X
  90. X    if ( backtrack_report )
  91. X        {
  92. X        fprintf( backtrack_file, "State #%d is non-accepting -\n", ds );
  93. X
  94. X        /* identify the state */
  95. X        dump_associated_rules( backtrack_file, ds );
  96. X
  97. X        /* now identify it further using the out- and jam-transitions */
  98. X        dump_transitions( backtrack_file, state );
  99. X
  100. X        putc( '\n', backtrack_file );
  101. X        }
  102. X    }
  103. X    }
  104. X
  105. X
  106. X/* check_trailing_context - check to see if NFA state set constitutes
  107. X *                          "dangerous" trailing context
  108. X *
  109. X * synopsis
  110. X *    int nfa_states[num_states+1], num_states;
  111. X *    int accset[nacc+1], nacc;
  112. X *    check_trailing_context( nfa_states, num_states, accset, nacc );
  113. X *
  114. X * NOTES
  115. X *    Trailing context is "dangerous" if both the head and the trailing
  116. X *  part are of variable size \and/ there's a DFA state which contains
  117. X *  both an accepting state for the head part of the rule and NFA states
  118. X *  which occur after the beginning of the trailing context.
  119. X *  When such a rule is matched, it's impossible to tell if having been
  120. X *  in the DFA state indicates the beginning of the trailing context
  121. X *  or further-along scanning of the pattern.  In these cases, a warning
  122. X *  message is issued.
  123. X *
  124. X *    nfa_states[1 .. num_states] is the list of NFA states in the DFA.
  125. X *    accset[1 .. nacc] is the list of accepting numbers for the DFA state.
  126. X */
  127. X
  128. Xvoid check_trailing_context( nfa_states, num_states, accset, nacc )
  129. Xint *nfa_states, num_states;
  130. Xint *accset;
  131. Xregister int nacc;
  132. X
  133. X    {
  134. X    register int i, j;
  135. X
  136. X    for ( i = 1; i <= num_states; ++i )
  137. X    {
  138. X    int ns = nfa_states[i];
  139. X    register int type = state_type[ns];
  140. X    register int ar = assoc_rule[ns];
  141. X
  142. X    if ( type == STATE_NORMAL || rule_type[ar] != RULE_VARIABLE )
  143. X        { /* do nothing */
  144. X        }
  145. X
  146. X    else if ( type == STATE_TRAILING_CONTEXT )
  147. X        {
  148. X        /* potential trouble.  Scan set of accepting numbers for
  149. X         * the one marking the end of the "head".  We assume that
  150. X         * this looping will be fairly cheap since it's rare that
  151. X         * an accepting number set is large.
  152. X         */
  153. X        for ( j = 1; j <= nacc; ++j )
  154. X        if ( accset[j] & YY_TRAILING_HEAD_MASK )
  155. X            {
  156. X            fprintf( stderr,
  157. X             "%s: Dangerous trailing context in rule at line %d\n",
  158. X                 program_name, rule_linenum[ar] );
  159. X            return;
  160. X            }
  161. X        }
  162. X    }
  163. X    }
  164. X
  165. X
  166. X/* dump_associated_rules - list the rules associated with a DFA state
  167. X *
  168. X * synopisis
  169. X *     int ds;
  170. X *     FILE *file;
  171. X *     dump_associated_rules( file, ds );
  172. X *
  173. X * goes through the set of NFA states associated with the DFA and
  174. X * extracts the first MAX_ASSOC_RULES unique rules, sorts them,
  175. X * and writes a report to the given file
  176. X */
  177. X
  178. Xvoid dump_associated_rules( file, ds )
  179. XFILE *file;
  180. Xint ds;
  181. X
  182. X    {
  183. X    register int i, j;
  184. X    register int num_associated_rules = 0;
  185. X    int rule_set[MAX_ASSOC_RULES + 1];
  186. X    int *dset = dss[ds];
  187. X    int size = dfasiz[ds];
  188. X    
  189. X    for ( i = 1; i <= size; ++i )
  190. X    {
  191. X    register rule_num = rule_linenum[assoc_rule[dset[i]]];
  192. X
  193. X    for ( j = 1; j <= num_associated_rules; ++j )
  194. X        if ( rule_num == rule_set[j] )
  195. X        break;
  196. X
  197. X    if ( j > num_associated_rules )
  198. X        { /* new rule */
  199. X        if ( num_associated_rules < MAX_ASSOC_RULES )
  200. X        rule_set[++num_associated_rules] = rule_num;
  201. X        }
  202. X    }
  203. X
  204. X    bubble( rule_set, num_associated_rules );
  205. X
  206. X    fprintf( file, " associated rule line numbers:" );
  207. X
  208. X    for ( i = 1; i <= num_associated_rules; ++i )
  209. X    {
  210. X    if ( i % 8 == 1 )
  211. X        putc( '\n', file );
  212. X    
  213. X    fprintf( file, "\t%d", rule_set[i] );
  214. X    }
  215. X    
  216. X    putc( '\n', file );
  217. X    }
  218. X
  219. X
  220. X/* dump_transitions - list the transitions associated with a DFA state
  221. X *
  222. X * synopisis
  223. X *     int state[numecs];
  224. X *     FILE *file;
  225. X *     dump_transitions( file, state );
  226. X *
  227. X * goes through the set of out-transitions and lists them in human-readable
  228. X * form (i.e., not as equivalence classes); also lists jam transitions
  229. X * (i.e., all those which are not out-transitions, plus EOF).  The dump
  230. X * is done to the given file.
  231. X */
  232. X
  233. Xvoid dump_transitions( file, state )
  234. XFILE *file;
  235. Xint state[];
  236. X
  237. X    {
  238. X    register int i, ec;
  239. X    int out_char_set[CSIZE];
  240. X
  241. X    for ( i = 0; i < csize; ++i )
  242. X    {
  243. X    ec = abs( ecgroup[i] );
  244. X    out_char_set[i] = state[ec];
  245. X    }
  246. X    
  247. X    fprintf( file, " out-transitions: " );
  248. X
  249. X    list_character_set( file, out_char_set );
  250. X
  251. X    /* now invert the members of the set to get the jam transitions */
  252. X    for ( i = 0; i < csize; ++i )
  253. X    out_char_set[i] = ! out_char_set[i];
  254. X
  255. X    fprintf( file, "\n jam-transitions: EOF " );
  256. X
  257. X    list_character_set( file, out_char_set );
  258. X
  259. X    putc( '\n', file );
  260. X    }
  261. X
  262. X
  263. X/* epsclosure - construct the epsilon closure of a set of ndfa states
  264. X *
  265. X * synopsis
  266. X *    int t[current_max_dfa_size], numstates, accset[num_rules + 1], nacc;
  267. X *    int hashval;
  268. X *    int *epsclosure();
  269. X *    t = epsclosure( t, &numstates, accset, &nacc, &hashval );
  270. X *
  271. X * NOTES
  272. X *    the epsilon closure is the set of all states reachable by an arbitrary
  273. X *  number of epsilon transitions which themselves do not have epsilon
  274. X *  transitions going out, unioned with the set of states which have non-null
  275. X *  accepting numbers.  t is an array of size numstates of nfa state numbers.
  276. X *  Upon return, t holds the epsilon closure and numstates is updated.  accset
  277. X *  holds a list of the accepting numbers, and the size of accset is given
  278. X *  by nacc.  t may be subjected to reallocation if it is not large enough
  279. X *  to hold the epsilon closure.
  280. X *
  281. X *    hashval is the hash value for the dfa corresponding to the state set
  282. X */
  283. X
  284. Xint *epsclosure( t, ns_addr, accset, nacc_addr, hv_addr )
  285. Xint *t, *ns_addr, accset[], *nacc_addr, *hv_addr;
  286. X
  287. X    {
  288. X    register int stkpos, ns, tsp;
  289. X    int numstates = *ns_addr, nacc, hashval, transsym, nfaccnum;
  290. X    int stkend, nstate;
  291. X    static int did_stk_init = false, *stk; 
  292. X
  293. X#define MARK_STATE(state) \
  294. X    trans1[state] = trans1[state] - MARKER_DIFFERENCE;
  295. X
  296. X#define IS_MARKED(state) (trans1[state] < 0)
  297. X
  298. X#define UNMARK_STATE(state) \
  299. X    trans1[state] = trans1[state] + MARKER_DIFFERENCE;
  300. X
  301. X#define CHECK_ACCEPT(state) \
  302. X    { \
  303. X    nfaccnum = accptnum[state]; \
  304. X    if ( nfaccnum != NIL ) \
  305. X        accset[++nacc] = nfaccnum; \
  306. X    }
  307. X
  308. X#define DO_REALLOCATION \
  309. X    { \
  310. X    current_max_dfa_size += MAX_DFA_SIZE_INCREMENT; \
  311. X    ++num_reallocs; \
  312. X    t = reallocate_integer_array( t, current_max_dfa_size ); \
  313. X    stk = reallocate_integer_array( stk, current_max_dfa_size ); \
  314. X    } \
  315. X
  316. X#define PUT_ON_STACK(state) \
  317. X    { \
  318. X    if ( ++stkend >= current_max_dfa_size ) \
  319. X        DO_REALLOCATION \
  320. X    stk[stkend] = state; \
  321. X    MARK_STATE(state) \
  322. X    }
  323. X
  324. X#define ADD_STATE(state) \
  325. X    { \
  326. X    if ( ++numstates >= current_max_dfa_size ) \
  327. X        DO_REALLOCATION \
  328. X    t[numstates] = state; \
  329. X    hashval = hashval + state; \
  330. X    }
  331. X
  332. X#define STACK_STATE(state) \
  333. X    { \
  334. X    PUT_ON_STACK(state) \
  335. X    CHECK_ACCEPT(state) \
  336. X    if ( nfaccnum != NIL || transchar[state] != SYM_EPSILON ) \
  337. X        ADD_STATE(state) \
  338. X    }
  339. X
  340. X    if ( ! did_stk_init )
  341. X    {
  342. X    stk = allocate_integer_array( current_max_dfa_size );
  343. X    did_stk_init = true;
  344. X    }
  345. X
  346. X    nacc = stkend = hashval = 0;
  347. X
  348. X    for ( nstate = 1; nstate <= numstates; ++nstate )
  349. X    {
  350. X    ns = t[nstate];
  351. X
  352. X    /* the state could be marked if we've already pushed it onto
  353. X     * the stack
  354. X     */
  355. X    if ( ! IS_MARKED(ns) )
  356. X        PUT_ON_STACK(ns)
  357. X
  358. X    CHECK_ACCEPT(ns)
  359. X    hashval = hashval + ns;
  360. X    }
  361. X
  362. X    for ( stkpos = 1; stkpos <= stkend; ++stkpos )
  363. X    {
  364. X    ns = stk[stkpos];
  365. X    transsym = transchar[ns];
  366. X
  367. X    if ( transsym == SYM_EPSILON )
  368. X        {
  369. X        tsp = trans1[ns] + MARKER_DIFFERENCE;
  370. X
  371. X        if ( tsp != NO_TRANSITION )
  372. X        {
  373. X        if ( ! IS_MARKED(tsp) )
  374. X            STACK_STATE(tsp)
  375. X
  376. X        tsp = trans2[ns];
  377. X
  378. X        if ( tsp != NO_TRANSITION )
  379. X            if ( ! IS_MARKED(tsp) )
  380. X            STACK_STATE(tsp)
  381. X        }
  382. X        }
  383. X    }
  384. X
  385. X    /* clear out "visit" markers */
  386. X
  387. X    for ( stkpos = 1; stkpos <= stkend; ++stkpos )
  388. X    {
  389. X    if ( IS_MARKED(stk[stkpos]) )
  390. X        {
  391. X        UNMARK_STATE(stk[stkpos])
  392. X        }
  393. X    else
  394. X        flexfatal( "consistency check failed in epsclosure()" );
  395. X    }
  396. X
  397. X    *ns_addr = numstates;
  398. X    *hv_addr = hashval;
  399. X    *nacc_addr = nacc;
  400. X
  401. X    return ( t );
  402. X    }
  403. X
  404. X
  405. X/* increase_max_dfas - increase the maximum number of DFAs */
  406. X
  407. Xvoid increase_max_dfas()
  408. X
  409. X    {
  410. X    current_max_dfas += MAX_DFAS_INCREMENT;
  411. X
  412. X    ++num_reallocs;
  413. X
  414. X    base = reallocate_integer_array( base, current_max_dfas );
  415. X    def = reallocate_integer_array( def, current_max_dfas );
  416. X    dfasiz = reallocate_integer_array( dfasiz, current_max_dfas );
  417. X    accsiz = reallocate_integer_array( accsiz, current_max_dfas );
  418. X    dhash = reallocate_integer_array( dhash, current_max_dfas );
  419. X    dss = reallocate_int_ptr_array( dss, current_max_dfas );
  420. X    dfaacc = reallocate_dfaacc_union( dfaacc, current_max_dfas );
  421. X
  422. X    if ( nultrans )
  423. X    nultrans = reallocate_integer_array( nultrans, current_max_dfas );
  424. X    }
  425. X
  426. X
  427. X/* ntod - convert an ndfa to a dfa
  428. X *
  429. X * synopsis
  430. X *    ntod();
  431. X *
  432. X *  creates the dfa corresponding to the ndfa we've constructed.  the
  433. X *  dfa starts out in state #1.
  434. X */
  435. X
  436. Xvoid ntod()
  437. X
  438. X    {
  439. X    int *accset, ds, nacc, newds;
  440. X    int sym, hashval, numstates, dsize;
  441. X    int num_full_table_rows;    /* used only for -f */
  442. X    int *nset, *dset;
  443. X    int targptr, totaltrans, i, comstate, comfreq, targ;
  444. X    int *epsclosure(), snstods(), symlist[CSIZE + 1];
  445. X    int num_start_states;
  446. X    int todo_head, todo_next;
  447. X
  448. X    /* note that the following are indexed by *equivalence classes*
  449. X     * and not by characters.  Since equivalence classes are indexed
  450. X     * beginning with 1, even if the scanner accepts NUL's, this
  451. X     * means that (since every character is potentially in its own
  452. X     * equivalence class) these arrays must have room for indices
  453. X     * from 1 to CSIZE, so their size must be CSIZE + 1.
  454. X     */
  455. X    int duplist[CSIZE + 1], state[CSIZE + 1];
  456. X    int targfreq[CSIZE + 1], targstate[CSIZE + 1];
  457. X
  458. X    /* this is so find_table_space(...) will know where to start looking in
  459. X     * chk/nxt for unused records for space to put in the state
  460. X     */
  461. X    if ( fullspd )
  462. X    firstfree = 0;
  463. X
  464. X    accset = allocate_integer_array( num_rules + 1 );
  465. X    nset = allocate_integer_array( current_max_dfa_size );
  466. X
  467. X    /* the "todo" queue is represented by the head, which is the DFA
  468. X     * state currently being processed, and the "next", which is the
  469. X     * next DFA state number available (not in use).  We depend on the
  470. X     * fact that snstods() returns DFA's \in increasing order/, and thus
  471. X     * need only know the bounds of the dfas to be processed.
  472. X     */
  473. X    todo_head = todo_next = 0;
  474. X
  475. X    for ( i = 0; i <= csize; ++i )
  476. X    {
  477. X    duplist[i] = NIL;
  478. X    symlist[i] = false;
  479. X    }
  480. X
  481. X    for ( i = 0; i <= num_rules; ++i )
  482. X    accset[i] = NIL;
  483. X
  484. X    if ( trace )
  485. X    {
  486. X    dumpnfa( scset[1] );
  487. X    fputs( "\n\nDFA Dump:\n\n", stderr );
  488. X    }
  489. X
  490. X    inittbl();
  491. X
  492. X    /* check to see whether we should build a separate table for transitions
  493. X     * on NUL characters.  We don't do this for full-speed (-F) scanners,
  494. X     * since for them we don't have a simple state number lying around with
  495. X     * which to index the table.  We also don't bother doing it for scanners
  496. X     * unless (1) NUL is in its own equivalence class (indicated by a
  497. X     * positive value of ecgroup[NUL]), (2) NUL's equilvalence class is
  498. X     * the last equivalence class, and (3) the number of equivalence classes
  499. X     * is the same as the number of characters.  This latter case comes about
  500. X     * when useecs is false or when its true but every character still
  501. X     * manages to land in its own class (unlikely, but it's cheap to check
  502. X     * for).  If all these things are true then the character code needed
  503. X     * to represent NUL's equivalence class for indexing the tables is
  504. X     * going to take one more bit than the number of characters, and therefore
  505. X     * we won't be assured of being able to fit it into a YY_CHAR variable.
  506. X     * This rules out storing the transitions in a compressed table, since
  507. X     * the code for interpreting them uses a YY_CHAR variable (perhaps it
  508. X     * should just use an integer, though; this is worth pondering ... ###).
  509. X     *
  510. X     * Finally, for full tables, we want the number of entries in the
  511. X     * table to be a power of two so the array references go fast (it
  512. X     * will just take a shift to compute the major index).  If encoding
  513. X     * NUL's transitions in the table will spoil this, we give it its
  514. X     * own table (note that this will be the case if we're not using
  515. X     * equivalence classes).
  516. X     */
  517. X
  518. X    /* note that the test for ecgroup[0] == numecs below accomplishes
  519. X     * both (1) and (2) above
  520. X     */
  521. X    if ( ! fullspd && ecgroup[0] == numecs )
  522. X    { /* NUL is alone in its equivalence class, which is the last one */
  523. X    int use_NUL_table = (numecs == csize);
  524. X
  525. X    if ( fulltbl && ! use_NUL_table )
  526. X        { /* we still may want to use the table if numecs is a power of 2 */
  527. X        int power_of_two;
  528. X
  529. X        for ( power_of_two = 1; power_of_two <= csize; power_of_two *= 2 )
  530. X        if ( numecs == power_of_two )
  531. X            {
  532. X            use_NUL_table = true;
  533. X            break;
  534. X            }
  535. X        }
  536. X
  537. X    if ( use_NUL_table )
  538. X        nultrans = allocate_integer_array( current_max_dfas );
  539. X        /* from now on, nultrans != nil indicates that we're
  540. X         * saving null transitions for later, separate encoding
  541. X         */
  542. X    }
  543. X
  544. X
  545. X    if ( fullspd )
  546. X    {
  547. X    for ( i = 0; i <= numecs; ++i )
  548. X        state[i] = 0;
  549. X    place_state( state, 0, 0 );
  550. X    }
  551. X
  552. X    else if ( fulltbl )
  553. X    {
  554. X    if ( nultrans )
  555. X        /* we won't be including NUL's transitions in the table,
  556. X         * so build it for entries from 0 .. numecs - 1
  557. X         */
  558. X        num_full_table_rows = numecs;
  559. X
  560. X    else
  561. X        /* take into account the fact that we'll be including
  562. X         * the NUL entries in the transition table.  Build it
  563. X         * from 0 .. numecs.
  564. X         */
  565. X        num_full_table_rows = numecs + 1;
  566. X
  567. X    /* declare it "short" because it's a real long-shot that that
  568. X     * won't be large enough.
  569. X     */
  570. X    printf( "static short int yy_nxt[][%d] =\n    {\n",
  571. X        /* '}' so vi doesn't get too confused */
  572. X        num_full_table_rows );
  573. X
  574. X    /* generate 0 entries for state #0 */
  575. X    for ( i = 0; i < num_full_table_rows; ++i )
  576. X        mk2data( 0 );
  577. X
  578. X    /* force ',' and dataflush() next call to mk2data */
  579. X    datapos = NUMDATAITEMS;
  580. X
  581. X    /* force extra blank line next dataflush() */
  582. X    dataline = NUMDATALINES;
  583. X    }
  584. X
  585. X    /* create the first states */
  586. X
  587. X    num_start_states = lastsc * 2;
  588. X
  589. X    for ( i = 1; i <= num_start_states; ++i )
  590. X    {
  591. X    numstates = 1;
  592. X
  593. X    /* for each start condition, make one state for the case when
  594. X     * we're at the beginning of the line (the '%' operator) and
  595. X     * one for the case when we're not
  596. X     */
  597. X    if ( i % 2 == 1 )
  598. X        nset[numstates] = scset[(i / 2) + 1];
  599. X    else
  600. X        nset[numstates] = mkbranch( scbol[i / 2], scset[i / 2] );
  601. X
  602. X    nset = epsclosure( nset, &numstates, accset, &nacc, &hashval );
  603. X
  604. X    if ( snstods( nset, numstates, accset, nacc, hashval, &ds ) )
  605. X        {
  606. X        numas += nacc;
  607. X        totnst += numstates;
  608. X        ++todo_next;
  609. X
  610. X        if ( variable_trailing_context_rules && nacc > 0 )
  611. X        check_trailing_context( nset, numstates, accset, nacc );
  612. X        }
  613. X    }
  614. X
  615. X    if ( ! fullspd )
  616. X    {
  617. X    if ( ! snstods( nset, 0, accset, 0, 0, &end_of_buffer_state ) )
  618. X        flexfatal( "could not create unique end-of-buffer state" );
  619. X
  620. X    ++numas;
  621. X    ++num_start_states;
  622. X    ++todo_next;
  623. X    }
  624. X
  625. X    while ( todo_head < todo_next )
  626. X    {
  627. X    targptr = 0;
  628. X    totaltrans = 0;
  629. X
  630. X    for ( i = 1; i <= numecs; ++i )
  631. X        state[i] = 0;
  632. X
  633. X    ds = ++todo_head;
  634. X
  635. X    dset = dss[ds];
  636. X    dsize = dfasiz[ds];
  637. X
  638. X    if ( trace )
  639. X        fprintf( stderr, "state # %d:\n", ds );
  640. X
  641. X    sympartition( dset, dsize, symlist, duplist );
  642. X
  643. X    for ( sym = 1; sym <= numecs; ++sym )
  644. X        {
  645. X        if ( symlist[sym] )
  646. X        {
  647. X        symlist[sym] = 0;
  648. X
  649. X        if ( duplist[sym] == NIL )
  650. X            { /* symbol has unique out-transitions */
  651. X            numstates = symfollowset( dset, dsize, sym, nset );
  652. X            nset = epsclosure( nset, &numstates, accset,
  653. X                       &nacc, &hashval );
  654. X
  655. X            if ( snstods( nset, numstates, accset,
  656. X                  nacc, hashval, &newds ) )
  657. X            {
  658. X            totnst = totnst + numstates;
  659. X            ++todo_next;
  660. X            numas += nacc;
  661. X
  662. X            if ( variable_trailing_context_rules && nacc > 0 )
  663. X                check_trailing_context( nset, numstates,
  664. X                accset, nacc );
  665. X            }
  666. X
  667. X            state[sym] = newds;
  668. X
  669. X            if ( trace )
  670. X            fprintf( stderr, "\t%d\t%d\n", sym, newds );
  671. X
  672. X            targfreq[++targptr] = 1;
  673. X            targstate[targptr] = newds;
  674. X            ++numuniq;
  675. X            }
  676. X
  677. X        else
  678. X            {
  679. X            /* sym's equivalence class has the same transitions
  680. X             * as duplist(sym)'s equivalence class
  681. X             */
  682. X            targ = state[duplist[sym]];
  683. X            state[sym] = targ;
  684. X
  685. X            if ( trace )
  686. X            fprintf( stderr, "\t%d\t%d\n", sym, targ );
  687. X
  688. X            /* update frequency count for destination state */
  689. X
  690. X            i = 0;
  691. X            while ( targstate[++i] != targ )
  692. X            ;
  693. X
  694. X            ++targfreq[i];
  695. X            ++numdup;
  696. X            }
  697. X
  698. X        ++totaltrans;
  699. X        duplist[sym] = NIL;
  700. X        }
  701. X        }
  702. X
  703. X    numsnpairs = numsnpairs + totaltrans;
  704. X
  705. X    if ( caseins && ! useecs )
  706. X        {
  707. X        register int j;
  708. X
  709. X        for ( i = 'A', j = 'a'; i <= 'Z'; ++i, ++j )
  710. X        state[i] = state[j];
  711. X        }
  712. X
  713. X    if ( ds > num_start_states )
  714. X        check_for_backtracking( ds, state );
  715. X
  716. X    if ( nultrans )
  717. X        {
  718. X        nultrans[ds] = state[NUL_ec];
  719. X        state[NUL_ec] = 0;    /* remove transition */
  720. X        }
  721. X
  722. X    if ( fulltbl )
  723. X        {
  724. X        /* supply array's 0-element */
  725. X        if ( ds == end_of_buffer_state )
  726. X        mk2data( -end_of_buffer_state );
  727. X        else
  728. X        mk2data( end_of_buffer_state );
  729. X
  730. X        for ( i = 1; i < num_full_table_rows; ++i )
  731. X        /* jams are marked by negative of state number */
  732. X        mk2data( state[i] ? state[i] : -ds );
  733. X
  734. X        /* force ',' and dataflush() next call to mk2data */
  735. X        datapos = NUMDATAITEMS;
  736. X
  737. X        /* force extra blank line next dataflush() */
  738. X        dataline = NUMDATALINES;
  739. X        }
  740. X
  741. X        else if ( fullspd )
  742. X        place_state( state, ds, totaltrans );
  743. X
  744. X    else if ( ds == end_of_buffer_state )
  745. X        /* special case this state to make sure it does what it's
  746. X         * supposed to, i.e., jam on end-of-buffer
  747. X         */
  748. X        stack1( ds, 0, 0, JAMSTATE );
  749. X
  750. X    else /* normal, compressed state */
  751. X        {
  752. X        /* determine which destination state is the most common, and
  753. X         * how many transitions to it there are
  754. X         */
  755. X
  756. X        comfreq = 0;
  757. X        comstate = 0;
  758. X
  759. X        for ( i = 1; i <= targptr; ++i )
  760. X        if ( targfreq[i] > comfreq )
  761. X            {
  762. X            comfreq = targfreq[i];
  763. X            comstate = targstate[i];
  764. X            }
  765. X
  766. X        bldtbl( state, ds, totaltrans, comstate, comfreq );
  767. X        }
  768. X    }
  769. X
  770. X    if ( fulltbl )
  771. X    dataend();
  772. X
  773. X    else if ( ! fullspd )
  774. X    {
  775. X    cmptmps();  /* create compressed template entries */
  776. X
  777. X    /* create tables for all the states with only one out-transition */
  778. X    while ( onesp > 0 )
  779. X        {
  780. X        mk1tbl( onestate[onesp], onesym[onesp], onenext[onesp],
  781. X            onedef[onesp] );
  782. X        --onesp;
  783. X        }
  784. X
  785. X    mkdeftbl();
  786. X    }
  787. X    }
  788. X
  789. X
  790. X/* snstods - converts a set of ndfa states into a dfa state
  791. X *
  792. X * synopsis
  793. X *    int sns[numstates], numstates, newds, accset[num_rules + 1], nacc, hashval;
  794. X *    int snstods();
  795. X *    is_new_state = snstods( sns, numstates, accset, nacc, hashval, &newds );
  796. X *
  797. X * on return, the dfa state number is in newds.
  798. X */
  799. X
  800. Xint snstods( sns, numstates, accset, nacc, hashval, newds_addr )
  801. Xint sns[], numstates, accset[], nacc, hashval, *newds_addr;
  802. X
  803. X    {
  804. X    int didsort = 0;
  805. X    register int i, j;
  806. X    int newds, *oldsns;
  807. X
  808. X    for ( i = 1; i <= lastdfa; ++i )
  809. X    if ( hashval == dhash[i] )
  810. X        {
  811. X        if ( numstates == dfasiz[i] )
  812. X        {
  813. X        oldsns = dss[i];
  814. X
  815. X        if ( ! didsort )
  816. X            {
  817. X            /* we sort the states in sns so we can compare it to
  818. X             * oldsns quickly.  we use bubble because there probably
  819. X             * aren't very many states
  820. X             */
  821. X            bubble( sns, numstates );
  822. X            didsort = 1;
  823. X            }
  824. X
  825. X        for ( j = 1; j <= numstates; ++j )
  826. X            if ( sns[j] != oldsns[j] )
  827. X            break;
  828. X
  829. X        if ( j > numstates )
  830. X            {
  831. X            ++dfaeql;
  832. X            *newds_addr = i;
  833. X            return ( 0 );
  834. X            }
  835. X
  836. X        ++hshcol;
  837. X        }
  838. X
  839. X        else
  840. X        ++hshsave;
  841. X        }
  842. X
  843. X    /* make a new dfa */
  844. X
  845. X    if ( ++lastdfa >= current_max_dfas )
  846. X    increase_max_dfas();
  847. X
  848. X    newds = lastdfa;
  849. X
  850. X    dss[newds] = (int *) malloc( (unsigned) ((numstates + 1) * sizeof( int )) );
  851. X
  852. X    if ( ! dss[newds] )
  853. X    flexfatal( "dynamic memory failure in snstods()" );
  854. X
  855. X    /* if we haven't already sorted the states in sns, we do so now, so that
  856. X     * future comparisons with it can be made quickly
  857. X     */
  858. X
  859. X    if ( ! didsort )
  860. X    bubble( sns, numstates );
  861. X
  862. X    for ( i = 1; i <= numstates; ++i )
  863. X    dss[newds][i] = sns[i];
  864. X
  865. X    dfasiz[newds] = numstates;
  866. X    dhash[newds] = hashval;
  867. X
  868. X    if ( nacc == 0 )
  869. X    {
  870. X    if ( reject )
  871. X        dfaacc[newds].dfaacc_set = (int *) 0;
  872. X    else
  873. X        dfaacc[newds].dfaacc_state = 0;
  874. X
  875. X    accsiz[newds] = 0;
  876. X    }
  877. X
  878. X    else if ( reject )
  879. X    {
  880. X    /* we sort the accepting set in increasing order so the disambiguating
  881. X     * rule that the first rule listed is considered match in the event of
  882. X     * ties will work.  We use a bubble sort since the list is probably
  883. X     * quite small.
  884. X     */
  885. X
  886. X    bubble( accset, nacc );
  887. X
  888. X    dfaacc[newds].dfaacc_set =
  889. X        (int *) malloc( (unsigned) ((nacc + 1) * sizeof( int )) );
  890. X
  891. X    if ( ! dfaacc[newds].dfaacc_set )
  892. X        flexfatal( "dynamic memory failure in snstods()" );
  893. X
  894. X    /* save the accepting set for later */
  895. X    for ( i = 1; i <= nacc; ++i )
  896. X        dfaacc[newds].dfaacc_set[i] = accset[i];
  897. X
  898. X    accsiz[newds] = nacc;
  899. X    }
  900. X
  901. X    else
  902. X    { /* find lowest numbered rule so the disambiguating rule will work */
  903. X    j = num_rules + 1;
  904. X
  905. X    for ( i = 1; i <= nacc; ++i )
  906. X        if ( accset[i] < j )
  907. X        j = accset[i];
  908. X
  909. X    dfaacc[newds].dfaacc_state = j;
  910. X    }
  911. X
  912. X    *newds_addr = newds;
  913. X
  914. X    return ( 1 );
  915. X    }
  916. X
  917. X
  918. X/* symfollowset - follow the symbol transitions one step
  919. X *
  920. X * synopsis
  921. X *    int ds[current_max_dfa_size], dsize, transsym;
  922. X *    int nset[current_max_dfa_size], numstates;
  923. X *    numstates = symfollowset( ds, dsize, transsym, nset );
  924. X */
  925. X
  926. Xint symfollowset( ds, dsize, transsym, nset )
  927. Xint ds[], dsize, transsym, nset[];
  928. X
  929. X    {
  930. X    int ns, tsp, sym, i, j, lenccl, ch, numstates;
  931. X    int ccllist;
  932. X
  933. X    numstates = 0;
  934. X
  935. X    for ( i = 1; i <= dsize; ++i )
  936. X    { /* for each nfa state ns in the state set of ds */
  937. X    ns = ds[i];
  938. X    sym = transchar[ns];
  939. X    tsp = trans1[ns];
  940. X
  941. X    if ( sym < 0 )
  942. X        { /* it's a character class */
  943. X        sym = -sym;
  944. X        ccllist = cclmap[sym];
  945. X        lenccl = ccllen[sym];
  946. X
  947. X        if ( cclng[sym] )
  948. X        {
  949. X        for ( j = 0; j < lenccl; ++j )
  950. X            { /* loop through negated character class */
  951. X            ch = ccltbl[ccllist + j];
  952. X
  953. X            if ( ch == 0 )
  954. X            ch = NUL_ec;
  955. X
  956. X            if ( ch > transsym )
  957. X            break;    /* transsym isn't in negated ccl */
  958. X
  959. X            else if ( ch == transsym )
  960. X            /* next 2 */ goto bottom;
  961. X            }
  962. X
  963. X        /* didn't find transsym in ccl */
  964. X        nset[++numstates] = tsp;
  965. X        }
  966. X
  967. X        else
  968. X        for ( j = 0; j < lenccl; ++j )
  969. X            {
  970. X            ch = ccltbl[ccllist + j];
  971. X
  972. X            if ( ch == 0 )
  973. X            ch = NUL_ec;
  974. X
  975. X            if ( ch > transsym )
  976. X            break;
  977. X
  978. X            else if ( ch == transsym )
  979. X            {
  980. X            nset[++numstates] = tsp;
  981. X            break;
  982. X            }
  983. X            }
  984. X        }
  985. X
  986. X    else if ( sym >= 'A' && sym <= 'Z' && caseins )
  987. X        flexfatal( "consistency check failed in symfollowset" );
  988. X
  989. X    else if ( sym == SYM_EPSILON )
  990. X        { /* do nothing */
  991. X        }
  992. X
  993. X    else if ( abs( ecgroup[sym] ) == transsym )
  994. X        nset[++numstates] = tsp;
  995. X
  996. Xbottom:
  997. X    ;
  998. X    }
  999. X
  1000. X    return ( numstates );
  1001. X    }
  1002. X
  1003. X
  1004. X/* sympartition - partition characters with same out-transitions
  1005. X *
  1006. X * synopsis
  1007. X *    integer ds[current_max_dfa_size], numstates, duplist[numecs];
  1008. X *    symlist[numecs];
  1009. X *    sympartition( ds, numstates, symlist, duplist );
  1010. X */
  1011. X
  1012. Xvoid sympartition( ds, numstates, symlist, duplist )
  1013. Xint ds[], numstates, duplist[];
  1014. Xint symlist[];
  1015. X
  1016. X    {
  1017. X    int tch, i, j, k, ns, dupfwd[CSIZE + 1], lenccl, cclp, ich;
  1018. X
  1019. X    /* partitioning is done by creating equivalence classes for those
  1020. X     * characters which have out-transitions from the given state.  Thus
  1021. X     * we are really creating equivalence classes of equivalence classes.
  1022. X     */
  1023. X
  1024. X    for ( i = 1; i <= numecs; ++i )
  1025. X    { /* initialize equivalence class list */
  1026. X    duplist[i] = i - 1;
  1027. X    dupfwd[i] = i + 1;
  1028. X    }
  1029. X
  1030. X    duplist[1] = NIL;
  1031. X    dupfwd[numecs] = NIL;
  1032. X
  1033. X    for ( i = 1; i <= numstates; ++i )
  1034. X    {
  1035. X    ns = ds[i];
  1036. X    tch = transchar[ns];
  1037. X
  1038. X    if ( tch != SYM_EPSILON )
  1039. X        {
  1040. X        if ( tch < -lastccl || tch > csize )
  1041. X        {
  1042. X        if ( tch > csize && tch <= CSIZE )
  1043. X            flexerror( "scanner requires -8 flag" );
  1044. X
  1045. X        else
  1046. X            flexfatal(
  1047. X            "bad transition character detected in sympartition()" );
  1048. X        }
  1049. X
  1050. X        if ( tch >= 0 )
  1051. X        { /* character transition */
  1052. X        /* abs() needed for fake %t ec's */
  1053. X        int ec = abs( ecgroup[tch] );
  1054. X
  1055. X        mkechar( ec, dupfwd, duplist );
  1056. X        symlist[ec] = 1;
  1057. X        }
  1058. X
  1059. X        else
  1060. X        { /* character class */
  1061. X        tch = -tch;
  1062. X
  1063. X        lenccl = ccllen[tch];
  1064. X        cclp = cclmap[tch];
  1065. X        mkeccl( ccltbl + cclp, lenccl, dupfwd, duplist, numecs,
  1066. X            NUL_ec );
  1067. X
  1068. X        if ( cclng[tch] )
  1069. X            {
  1070. X            j = 0;
  1071. X
  1072. X            for ( k = 0; k < lenccl; ++k )
  1073. X            {
  1074. X            ich = ccltbl[cclp + k];
  1075. X
  1076. X            if ( ich == 0 )
  1077. X                ich = NUL_ec;
  1078. X
  1079. X            for ( ++j; j < ich; ++j )
  1080. X                symlist[j] = 1;
  1081. X            }
  1082. X
  1083. X            for ( ++j; j <= numecs; ++j )
  1084. X            symlist[j] = 1;
  1085. X            }
  1086. X
  1087. X        else
  1088. X            for ( k = 0; k < lenccl; ++k )
  1089. X            {
  1090. X            ich = ccltbl[cclp + k];
  1091. X
  1092. X            if ( ich == 0 )
  1093. X                ich = NUL_ec;
  1094. X
  1095. X            symlist[ich] = 1;
  1096. X            }
  1097. X        }
  1098. X        }
  1099. X    }
  1100. X    }
  1101. END_OF_FILE
  1102.   if test 26919 -ne `wc -c <'dfa.c'`; then
  1103.     echo shar: \"'dfa.c'\" unpacked with wrong size!
  1104.   fi
  1105.   # end of 'dfa.c'
  1106. fi
  1107. if test -f 'flex.skel' -a "${1}" != "-c" ; then 
  1108.   echo shar: Will not clobber existing file \"'flex.skel'\"
  1109. else
  1110.   echo shar: Extracting \"'flex.skel'\" \(19796 characters\)
  1111.   sed "s/^X//" >'flex.skel' <<'END_OF_FILE'
  1112. X/* A lexical scanner generated by flex */
  1113. X
  1114. X/* scanner skeleton version:
  1115. X * $Header: /usr/fsys/odin/a/vern/flex/RCS/flex.skel,v 2.16 90/08/03 14:09:36 vern Exp $
  1116. X */
  1117. X
  1118. X#define FLEX_SCANNER
  1119. X
  1120. X#include <stdio.h>
  1121. X
  1122. X
  1123. X/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
  1124. X#ifdef c_plusplus
  1125. X#ifndef __cplusplus
  1126. X#define __cplusplus
  1127. X#endif
  1128. X#endif
  1129. X
  1130. X
  1131. X#ifdef __cplusplus
  1132. X
  1133. X#include <stdlib.h>
  1134. X#include <osfcn.h>
  1135. X
  1136. X/* use prototypes in function declarations */
  1137. X#define YY_USE_PROTOS
  1138. X
  1139. X/* the "const" storage-class-modifier is valid */
  1140. X#define YY_USE_CONST
  1141. X
  1142. X#else    /* ! __cplusplus */
  1143. X
  1144. X#ifdef __STDC__
  1145. X
  1146. X#ifdef __GNUC__
  1147. X#include <stddef.h>
  1148. Xvoid *malloc( size_t );
  1149. Xvoid free( void* );
  1150. X#else
  1151. X#include <stdlib.h>
  1152. X#endif    /* __GNUC__ */
  1153. X
  1154. X#define YY_USE_PROTOS
  1155. X#define YY_USE_CONST
  1156. X
  1157. X#endif    /* __STDC__ */
  1158. X#endif    /* ! __cplusplus */
  1159. X
  1160. X
  1161. X#ifdef __TURBOC__
  1162. X#define YY_USE_CONST
  1163. X#endif
  1164. X
  1165. X
  1166. X#ifndef YY_USE_CONST
  1167. X#define const
  1168. X#endif
  1169. X
  1170. X
  1171. X#ifdef YY_USE_PROTOS
  1172. X#define YY_PROTO(proto) proto
  1173. X#else
  1174. X#define YY_PROTO(proto) ()
  1175. X/* we can't get here if it's an ANSI C compiler, or a C++ compiler,
  1176. X * so it's got to be a K&R compiler, and therefore there's no standard
  1177. X * place from which to include these definitions
  1178. X */
  1179. Xchar *malloc();
  1180. Xint free();
  1181. Xint read();
  1182. X#endif
  1183. X
  1184. X
  1185. X/* amount of stuff to slurp up with each read */
  1186. X#ifndef YY_READ_BUF_SIZE
  1187. X#define YY_READ_BUF_SIZE 8192
  1188. X#endif
  1189. X
  1190. X/* returned upon end-of-file */
  1191. X#define YY_END_TOK 0
  1192. X
  1193. X/* copy whatever the last rule matched to the standard output */
  1194. X
  1195. X/* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */
  1196. X/* this used to be an fputs(), but since the string might contain NUL's,
  1197. X * we now use fwrite()
  1198. X */
  1199. X#define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout )
  1200. X
  1201. X/* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
  1202. X * is returned in "result".
  1203. X */
  1204. X#define YY_INPUT(buf,result,max_size) \
  1205. X    if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
  1206. X        YY_FATAL_ERROR( "read() in flex scanner failed" );
  1207. X#define YY_NULL 0
  1208. X
  1209. X/* no semi-colon after return; correct usage is to write "yyterminate();" -
  1210. X * we don't want an extra ';' after the "return" because that will cause
  1211. X * some compilers to complain about unreachable statements.
  1212. X */
  1213. X#define yyterminate() return ( YY_NULL )
  1214. X
  1215. X/* report a fatal error */
  1216. X
  1217. X/* The funky do-while is used to turn this macro definition into
  1218. X * a single C statement (which needs a semi-colon terminator).
  1219. X * This avoids problems with code like:
  1220. X *
  1221. X *     if ( something_happens )
  1222. X *        YY_FATAL_ERROR( "oops, the something happened" );
  1223. X *    else
  1224. X *        everything_okay();
  1225. X *
  1226. X * Prior to using the do-while the compiler would get upset at the
  1227. X * "else" because it interpreted the "if" statement as being all
  1228. X * done when it reached the ';' after the YY_FATAL_ERROR() call.
  1229. X */
  1230. X
  1231. X#define YY_FATAL_ERROR(msg) \
  1232. X    do \
  1233. X        { \
  1234. X        (void) fputs( msg, stderr ); \
  1235. X        (void) putc( '\n', stderr ); \
  1236. X        exit( 1 ); \
  1237. X        } \
  1238. X    while ( 0 )
  1239. X
  1240. X/* default yywrap function - always treat EOF as an EOF */
  1241. X#define yywrap() 1
  1242. X
  1243. X/* enter a start condition.  This macro really ought to take a parameter,
  1244. X * but we do it the disgusting crufty way forced on us by the ()-less
  1245. X * definition of BEGIN
  1246. X */
  1247. X#define BEGIN yy_start = 1 + 2 *
  1248. X
  1249. X/* action number for EOF rule of a given start state */
  1250. X#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
  1251. X
  1252. X/* special action meaning "start processing a new file" */
  1253. X#define YY_NEW_FILE \
  1254. X    do \
  1255. X        { \
  1256. X        yy_init_buffer( yy_current_buffer, yyin ); \
  1257. X        yy_load_buffer_state(); \
  1258. X        } \
  1259. X    while ( 0 )
  1260. X
  1261. X/* default declaration of generated scanner - a define so the user can
  1262. X * easily add parameters
  1263. X */
  1264. X#define YY_DECL int yylex YY_PROTO(( void )) 
  1265. X
  1266. X/* code executed at the end of each rule */
  1267. X#define YY_BREAK break;
  1268. X
  1269. X#define YY_END_OF_BUFFER_CHAR 0
  1270. X
  1271. X#ifndef YY_BUF_SIZE
  1272. X#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */
  1273. X#endif
  1274. X
  1275. Xtypedef struct yy_buffer_state *YY_BUFFER_STATE;
  1276. X
  1277. X%% section 1 definitions go here
  1278. X
  1279. X/* done after the current pattern has been matched and before the
  1280. X * corresponding action - sets up yytext
  1281. X */
  1282. X#define YY_DO_BEFORE_ACTION \
  1283. X    yytext = yy_bp; \
  1284. X%% code to fiddle yytext and yyleng for yymore() goes here
  1285. X    yy_hold_char = *yy_cp; \
  1286. X    *yy_cp = '\0'; \
  1287. X    yy_c_buf_p = yy_cp;
  1288. X
  1289. X#define EOB_ACT_CONTINUE_SCAN 0
  1290. X#define EOB_ACT_END_OF_FILE 1
  1291. X#define EOB_ACT_LAST_MATCH 2
  1292. X
  1293. X/* return all but the first 'n' matched characters back to the input stream */
  1294. X#define yyless(n) \
  1295. X    do \
  1296. X        { \
  1297. X        /* undo effects of setting up yytext */ \
  1298. X        *yy_cp = yy_hold_char; \
  1299. X        yy_c_buf_p = yy_cp = yy_bp + n; \
  1300. X        YY_DO_BEFORE_ACTION; /* set up yytext again */ \
  1301. X        } \
  1302. X    while ( 0 )
  1303. X
  1304. X#define unput(c) yyunput( c, yytext )
  1305. X
  1306. X
  1307. Xstruct yy_buffer_state
  1308. X    {
  1309. X    FILE *yy_input_file;
  1310. X
  1311. X    YY_CHAR *yy_ch_buf;        /* input buffer */
  1312. X    YY_CHAR *yy_buf_pos;    /* current position in input buffer */
  1313. X
  1314. X    /* size of input buffer in bytes, not including room for EOB characters*/
  1315. X    int yy_buf_size;    
  1316. X
  1317. X    /* number of characters read into yy_ch_buf, not including EOB characters */
  1318. X    int yy_n_chars;
  1319. X
  1320. X    int yy_eof_status;        /* whether we've seen an EOF on this buffer */
  1321. X#define EOF_NOT_SEEN 0
  1322. X    /* "pending" happens when the EOF has been seen but there's still
  1323. X     * some text process
  1324. X     */
  1325. X#define EOF_PENDING 1
  1326. X#define EOF_DONE 2
  1327. X    };
  1328. X
  1329. Xstatic YY_BUFFER_STATE yy_current_buffer;
  1330. X
  1331. X/* we provide macros for accessing buffer states in case in the
  1332. X * future we want to put the buffer states in a more general
  1333. X * "scanner state"
  1334. X */
  1335. X#define YY_CURRENT_BUFFER yy_current_buffer
  1336. X
  1337. X
  1338. X/* yy_hold_char holds the character lost when yytext is formed */
  1339. Xstatic YY_CHAR yy_hold_char;
  1340. X
  1341. Xstatic int yy_n_chars;        /* number of characters read into yy_ch_buf */
  1342. X
  1343. X
  1344. X
  1345. X#ifndef YY_USER_ACTION
  1346. X#define YY_USER_ACTION
  1347. X#endif
  1348. X
  1349. X#ifndef YY_USER_INIT
  1350. X#define YY_USER_INIT
  1351. X#endif
  1352. X
  1353. Xextern YY_CHAR *yytext;
  1354. Xextern int yyleng;
  1355. Xextern FILE *yyin, *yyout;
  1356. X
  1357. XYY_CHAR *yytext;
  1358. Xint yyleng;
  1359. X
  1360. XFILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
  1361. X
  1362. X%% data tables for the DFA go here
  1363. X
  1364. X/* these variables are all declared out here so that section 3 code can
  1365. X * manipulate them
  1366. X */
  1367. X/* points to current character in buffer */
  1368. Xstatic YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0;
  1369. Xstatic int yy_init = 1;        /* whether we need to initialize */
  1370. Xstatic int yy_start = 0;    /* start state number */
  1371. X
  1372. X/* flag which is used to allow yywrap()'s to do buffer switches
  1373. X * instead of setting up a fresh yyin.  A bit of a hack ...
  1374. X */
  1375. Xstatic int yy_did_buffer_switch_on_eof;
  1376. X
  1377. Xstatic yy_state_type yy_get_previous_state YY_PROTO(( void ));
  1378. Xstatic yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
  1379. Xstatic int yy_get_next_buffer YY_PROTO(( void ));
  1380. Xstatic void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr ));
  1381. Xvoid yyrestart YY_PROTO(( FILE *input_file ));
  1382. Xvoid yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
  1383. Xvoid yy_load_buffer_state YY_PROTO(( void ));
  1384. XYY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
  1385. Xvoid yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
  1386. Xvoid yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
  1387. X
  1388. X#define yy_new_buffer yy_create_buffer
  1389. X
  1390. X#ifdef __cplusplus
  1391. Xstatic int yyinput YY_PROTO(( void ));
  1392. X#else
  1393. Xstatic int input YY_PROTO(( void ));
  1394. X#endif
  1395. X
  1396. XYY_DECL
  1397. X    {
  1398. X    register yy_state_type yy_current_state;
  1399. X    register YY_CHAR *yy_cp, *yy_bp;
  1400. X    register int yy_act;
  1401. X
  1402. X%% user's declarations go here
  1403. X
  1404. X    if ( yy_init )
  1405. X    {
  1406. X    YY_USER_INIT;
  1407. X
  1408. X    if ( ! yy_start )
  1409. X        yy_start = 1;    /* first start state */
  1410. X
  1411. X    if ( ! yyin )
  1412. X        yyin = stdin;
  1413. X
  1414. X    if ( ! yyout )
  1415. X        yyout = stdout;
  1416. X
  1417. X    if ( yy_current_buffer )
  1418. X        yy_init_buffer( yy_current_buffer, yyin );
  1419. X    else
  1420. X        yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
  1421. X
  1422. X    yy_load_buffer_state();
  1423. X
  1424. X    yy_init = 0;
  1425. X    }
  1426. X
  1427. X    while ( 1 )        /* loops until end-of-file is reached */
  1428. X    {
  1429. X%% yymore()-related code goes here
  1430. X    yy_cp = yy_c_buf_p;
  1431. X
  1432. X    /* support of yytext */
  1433. X    *yy_cp = yy_hold_char;
  1434. X
  1435. X    /* yy_bp points to the position in yy_ch_buf of the start of the
  1436. X     * current run.
  1437. X     */
  1438. X    yy_bp = yy_cp;
  1439. X
  1440. X%% code to set up and find next match goes here
  1441. X
  1442. Xyy_find_action:
  1443. X%% code to find the action number goes here
  1444. X
  1445. X    YY_DO_BEFORE_ACTION;
  1446. X    YY_USER_ACTION;
  1447. X
  1448. Xdo_action:    /* this label is used only to access EOF actions */
  1449. X
  1450. X%% debug code goes here
  1451. X
  1452. X    switch ( yy_act )
  1453. X        {
  1454. X%% actions go here
  1455. X
  1456. X        case YY_END_OF_BUFFER:
  1457. X        {
  1458. X        /* amount of text matched not including the EOB char */
  1459. X        int yy_amount_of_matched_text = yy_cp - yytext - 1;
  1460. X
  1461. X        /* undo the effects of YY_DO_BEFORE_ACTION */
  1462. X        *yy_cp = yy_hold_char;
  1463. X
  1464. X        /* note that here we test for yy_c_buf_p "<=" to the position
  1465. X         * of the first EOB in the buffer, since yy_c_buf_p will
  1466. X         * already have been incremented past the NUL character
  1467. X         * (since all states make transitions on EOB to the end-
  1468. X         * of-buffer state).  Contrast this with the test in yyinput().
  1469. X         */
  1470. X        if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
  1471. X            /* this was really a NUL */
  1472. X            {
  1473. X            yy_state_type yy_next_state;
  1474. X
  1475. X            yy_c_buf_p = yytext + yy_amount_of_matched_text;
  1476. X
  1477. X            yy_current_state = yy_get_previous_state();
  1478. X
  1479. X            /* okay, we're now positioned to make the
  1480. X             * NUL transition.  We couldn't have
  1481. X             * yy_get_previous_state() go ahead and do it
  1482. X             * for us because it doesn't know how to deal
  1483. X             * with the possibility of jamming (and we
  1484. X             * don't want to build jamming into it because
  1485. X             * then it will run more slowly)
  1486. X             */
  1487. X
  1488. X            yy_next_state = yy_try_NUL_trans( yy_current_state );
  1489. X
  1490. X            yy_bp = yytext + YY_MORE_ADJ;
  1491. X
  1492. X            if ( yy_next_state )
  1493. X            {
  1494. X            /* consume the NUL */
  1495. X            yy_cp = ++yy_c_buf_p;
  1496. X            yy_current_state = yy_next_state;
  1497. X            goto yy_match;
  1498. X            }
  1499. X
  1500. X            else
  1501. X            {
  1502. X%% code to do backtracking for compressed tables and set up yy_cp goes here
  1503. X            goto yy_find_action;
  1504. X            }
  1505. X            }
  1506. X
  1507. X        else switch ( yy_get_next_buffer() )
  1508. X            {
  1509. X            case EOB_ACT_END_OF_FILE:
  1510. X            {
  1511. X            yy_did_buffer_switch_on_eof = 0;
  1512. X
  1513. X            if ( yywrap() )
  1514. X                {
  1515. X                /* note: because we've taken care in
  1516. X                 * yy_get_next_buffer() to have set up yytext,
  1517. X                 * we can now set up yy_c_buf_p so that if some
  1518. X                 * total hoser (like flex itself) wants
  1519. X                 * to call the scanner after we return the
  1520. X                 * YY_NULL, it'll still work - another YY_NULL
  1521. X                 * will get returned.
  1522. X                 */
  1523. X                yy_c_buf_p = yytext + YY_MORE_ADJ;
  1524. X
  1525. X                yy_act = YY_STATE_EOF((yy_start - 1) / 2);
  1526. X                goto do_action;
  1527. X                }
  1528. X
  1529. X            else
  1530. X                {
  1531. X                if ( ! yy_did_buffer_switch_on_eof )
  1532. X                YY_NEW_FILE;
  1533. X                }
  1534. X            }
  1535. X            break;
  1536. X
  1537. X            case EOB_ACT_CONTINUE_SCAN:
  1538. X            yy_c_buf_p = yytext + yy_amount_of_matched_text;
  1539. X
  1540. X            yy_current_state = yy_get_previous_state();
  1541. X
  1542. X            yy_cp = yy_c_buf_p;
  1543. X            yy_bp = yytext + YY_MORE_ADJ;
  1544. X            goto yy_match;
  1545. X
  1546. X            case EOB_ACT_LAST_MATCH:
  1547. X            yy_c_buf_p =
  1548. X                &yy_current_buffer->yy_ch_buf[yy_n_chars];
  1549. X
  1550. X            yy_current_state = yy_get_previous_state();
  1551. X
  1552. X            yy_cp = yy_c_buf_p;
  1553. X            yy_bp = yytext + YY_MORE_ADJ;
  1554. X            goto yy_find_action;
  1555. X            }
  1556. X        break;
  1557. X        }
  1558. X
  1559. X        default:
  1560. X#ifdef FLEX_DEBUG
  1561. X        printf( "action # %d\n", yy_act );
  1562. X#endif
  1563. X        YY_FATAL_ERROR(
  1564. X            "fatal flex scanner internal error--no action found" );
  1565. X        }
  1566. X    }
  1567. X    }
  1568. X
  1569. X
  1570. X/* yy_get_next_buffer - try to read in a new buffer
  1571. X *
  1572. X * synopsis
  1573. X *     int yy_get_next_buffer();
  1574. X *     
  1575. X * returns a code representing an action
  1576. X *     EOB_ACT_LAST_MATCH - 
  1577. X *     EOB_ACT_CONTINUE_SCAN - continue scanning from current position
  1578. X *     EOB_ACT_END_OF_FILE - end of file
  1579. X */
  1580. X
  1581. Xstatic int yy_get_next_buffer()
  1582. X
  1583. X    {
  1584. X    register YY_CHAR *dest = yy_current_buffer->yy_ch_buf;
  1585. X    register YY_CHAR *source = yytext - 1; /* copy prev. char, too */
  1586. X    register int number_to_move, i;
  1587. X    int ret_val;
  1588. X
  1589. X    if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
  1590. X    YY_FATAL_ERROR(
  1591. X        "fatal flex scanner internal error--end of buffer missed" );
  1592. X
  1593. X    /* try to read more data */
  1594. X
  1595. X    /* first move last chars to start of buffer */
  1596. X    number_to_move = yy_c_buf_p - yytext;
  1597. X
  1598. X    for ( i = 0; i < number_to_move; ++i )
  1599. X    *(dest++) = *(source++);
  1600. X
  1601. X    if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN )
  1602. X    /* don't do the read, it's not guaranteed to return an EOF,
  1603. X     * just force an EOF
  1604. X     */
  1605. X    yy_n_chars = 0;
  1606. X
  1607. X    else
  1608. X    {
  1609. X    int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1;
  1610. X
  1611. X    if ( num_to_read > YY_READ_BUF_SIZE )
  1612. X        num_to_read = YY_READ_BUF_SIZE;
  1613. X
  1614. X    else if ( num_to_read <= 0 )
  1615. X        YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
  1616. X
  1617. X    /* read in more data */
  1618. X    YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
  1619. X          yy_n_chars, num_to_read );
  1620. X    }
  1621. X
  1622. X    if ( yy_n_chars == 0 )
  1623. X    {
  1624. X    if ( number_to_move == 1 )
  1625. X        {
  1626. X        ret_val = EOB_ACT_END_OF_FILE;
  1627. X        yy_current_buffer->yy_eof_status = EOF_DONE;
  1628. X        }
  1629. X
  1630. X    else
  1631. X        {
  1632. X        ret_val = EOB_ACT_LAST_MATCH;
  1633. X        yy_current_buffer->yy_eof_status = EOF_PENDING;
  1634. X        }
  1635. X    }
  1636. X
  1637. X    else
  1638. X    ret_val = EOB_ACT_CONTINUE_SCAN;
  1639. X
  1640. X    yy_n_chars += number_to_move;
  1641. X    yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  1642. X    yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  1643. X
  1644. X    /* yytext begins at the second character in yy_ch_buf; the first
  1645. X     * character is the one which preceded it before reading in the latest
  1646. X     * buffer; it needs to be kept around in case it's a newline, so
  1647. X     * yy_get_previous_state() will have with '^' rules active
  1648. X     */
  1649. X
  1650. X    yytext = &yy_current_buffer->yy_ch_buf[1];
  1651. X
  1652. X    return ( ret_val );
  1653. X    }
  1654. X
  1655. X
  1656. X/* yy_get_previous_state - get the state just before the EOB char was reached
  1657. X *
  1658. X * synopsis
  1659. X *     yy_state_type yy_get_previous_state();
  1660. X */
  1661. X
  1662. Xstatic yy_state_type yy_get_previous_state()
  1663. X
  1664. X    {
  1665. X    register yy_state_type yy_current_state;
  1666. X    register YY_CHAR *yy_cp;
  1667. X
  1668. X%% code to get the start state into yy_current_state goes here
  1669. X
  1670. X    for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
  1671. X    {
  1672. X%% code to find the next state goes here
  1673. X    }
  1674. X
  1675. X    return ( yy_current_state );
  1676. X    }
  1677. X
  1678. X
  1679. X/* yy_try_NUL_trans - try to make a transition on the NUL character
  1680. X *
  1681. X * synopsis
  1682. X *     next_state = yy_try_NUL_trans( current_state );
  1683. X */
  1684. X
  1685. X#ifdef YY_USE_PROTOS
  1686. Xstatic yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state )
  1687. X#else
  1688. Xstatic yy_state_type yy_try_NUL_trans( yy_current_state )
  1689. Xregister yy_state_type yy_current_state;
  1690. X#endif
  1691. X
  1692. X    {
  1693. X    register int yy_is_jam;
  1694. X%% code to find the next state, and perhaps do backtracking, goes here
  1695. X
  1696. X    return ( yy_is_jam ? 0 : yy_current_state );
  1697. X    }
  1698. X
  1699. X
  1700. X#ifdef YY_USE_PROTOS
  1701. Xstatic void yyunput( YY_CHAR c, register YY_CHAR *yy_bp )
  1702. X#else
  1703. Xstatic void yyunput( c, yy_bp )
  1704. XYY_CHAR c;
  1705. Xregister YY_CHAR *yy_bp;
  1706. X#endif
  1707. X
  1708. X    {
  1709. X    register YY_CHAR *yy_cp = yy_c_buf_p;
  1710. X
  1711. X    /* undo effects of setting up yytext */
  1712. X    *yy_cp = yy_hold_char;
  1713. X
  1714. X    if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
  1715. X    { /* need to shift things up to make room */
  1716. X    register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
  1717. X    register YY_CHAR *dest =
  1718. X        &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2];
  1719. X    register YY_CHAR *source =
  1720. X        &yy_current_buffer->yy_ch_buf[number_to_move];
  1721. X
  1722. X    while ( source > yy_current_buffer->yy_ch_buf )
  1723. X        *--dest = *--source;
  1724. X
  1725. X    yy_cp += dest - source;
  1726. X    yy_bp += dest - source;
  1727. X    yy_n_chars = yy_current_buffer->yy_buf_size;
  1728. X
  1729. X    if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
  1730. X        YY_FATAL_ERROR( "flex scanner push-back overflow" );
  1731. X    }
  1732. X
  1733. X    if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
  1734. X    yy_cp[-2] = '\n';
  1735. X
  1736. X    *--yy_cp = c;
  1737. X
  1738. X    /* note: the formal parameter *must* be called "yy_bp" for this
  1739. X     *       macro to now work correctly
  1740. X     */
  1741. X    YY_DO_BEFORE_ACTION; /* set up yytext again */
  1742. X    }
  1743. X
  1744. X
  1745. X#ifdef __cplusplus
  1746. Xstatic int yyinput()
  1747. X#else
  1748. Xstatic int input()
  1749. X#endif
  1750. X
  1751. X    {
  1752. X    int c;
  1753. X    YY_CHAR *yy_cp = yy_c_buf_p;
  1754. X
  1755. X    *yy_cp = yy_hold_char;
  1756. X
  1757. X    if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
  1758. X    {
  1759. X    /* yy_c_buf_p now points to the character we want to return.
  1760. X     * If this occurs *before* the EOB characters, then it's a
  1761. X     * valid NUL; if not, then we've hit the end of the buffer.
  1762. X     */
  1763. X    if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
  1764. X        /* this was really a NUL */
  1765. X        *yy_c_buf_p = '\0';
  1766. X
  1767. X    else
  1768. X        { /* need more input */
  1769. X        yytext = yy_c_buf_p;
  1770. X        ++yy_c_buf_p;
  1771. X
  1772. X        switch ( yy_get_next_buffer() )
  1773. X        {
  1774. X        case EOB_ACT_END_OF_FILE:
  1775. X            {
  1776. X            if ( yywrap() )
  1777. X            {
  1778. X            yy_c_buf_p = yytext + YY_MORE_ADJ;
  1779. X            return ( EOF );
  1780. X            }
  1781. X
  1782. X            YY_NEW_FILE;
  1783. X
  1784. X#ifdef __cplusplus
  1785. X            return ( yyinput() );
  1786. X#else
  1787. X            return ( input() );
  1788. X#endif
  1789. X            }
  1790. X            break;
  1791. X
  1792. X        case EOB_ACT_CONTINUE_SCAN:
  1793. X            yy_c_buf_p = yytext + YY_MORE_ADJ;
  1794. X            break;
  1795. X
  1796. X        case EOB_ACT_LAST_MATCH:
  1797. X#ifdef __cplusplus
  1798. X            YY_FATAL_ERROR( "unexpected last match in yyinput()" );
  1799. X#else
  1800. X            YY_FATAL_ERROR( "unexpected last match in input()" );
  1801. X#endif
  1802. X        }
  1803. X        }
  1804. X    }
  1805. X
  1806. X    c = *yy_c_buf_p;
  1807. X    yy_hold_char = *++yy_c_buf_p;
  1808. X
  1809. X    return ( c );
  1810. X    }
  1811. X
  1812. X
  1813. X#ifdef YY_USE_PROTOS
  1814. Xvoid yyrestart( FILE *input_file )
  1815. X#else
  1816. Xvoid yyrestart( input_file )
  1817. XFILE *input_file;
  1818. X#endif
  1819. X
  1820. X    {
  1821. X    yy_init_buffer( yy_current_buffer, input_file );
  1822. X    yy_load_buffer_state();
  1823. X    }
  1824. X
  1825. X
  1826. X#ifdef YY_USE_PROTOS
  1827. Xvoid yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
  1828. X#else
  1829. Xvoid yy_switch_to_buffer( new_buffer )
  1830. XYY_BUFFER_STATE new_buffer;
  1831. X#endif
  1832. X
  1833. X    {
  1834. X    if ( yy_current_buffer == new_buffer )
  1835. X    return;
  1836. X
  1837. X    if ( yy_current_buffer )
  1838. X    {
  1839. X    /* flush out information for old buffer */
  1840. X    *yy_c_buf_p = yy_hold_char;
  1841. X    yy_current_buffer->yy_buf_pos = yy_c_buf_p;
  1842. X    yy_current_buffer->yy_n_chars = yy_n_chars;
  1843. X    }
  1844. X
  1845. X    yy_current_buffer = new_buffer;
  1846. X    yy_load_buffer_state();
  1847. X
  1848. X    /* we don't actually know whether we did this switch during
  1849. X     * EOF (yywrap()) processing, but the only time this flag
  1850. X     * is looked at is after yywrap() is called, so it's safe
  1851. X     * to go ahead and always set it.
  1852. X     */
  1853. X    yy_did_buffer_switch_on_eof = 1;
  1854. X    }
  1855. X
  1856. X
  1857. X#ifdef YY_USE_PROTOS
  1858. Xvoid yy_load_buffer_state( void )
  1859. X#else
  1860. Xvoid yy_load_buffer_state()
  1861. X#endif
  1862. X
  1863. X    {
  1864. X    yy_n_chars = yy_current_buffer->yy_n_chars;
  1865. X    yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
  1866. X    yyin = yy_current_buffer->yy_input_file;
  1867. X    yy_hold_char = *yy_c_buf_p;
  1868. X    }
  1869. X
  1870. X
  1871. X#ifdef YY_USE_PROTOS
  1872. XYY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
  1873. X#else
  1874. XYY_BUFFER_STATE yy_create_buffer( file, size )
  1875. XFILE *file;
  1876. Xint size;
  1877. X#endif
  1878. X
  1879. X    {
  1880. X    YY_BUFFER_STATE b;
  1881. X
  1882. X    b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
  1883. X
  1884. X    if ( ! b )
  1885. X    YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
  1886. X
  1887. X    b->yy_buf_size = size;
  1888. X
  1889. X    /* yy_ch_buf has to be 2 characters longer than the size given because
  1890. X     * we need to put in 2 end-of-buffer characters.
  1891. X     */
  1892. X    b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) );
  1893. X
  1894. X    if ( ! b->yy_ch_buf )
  1895. X    YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
  1896. X
  1897. X    yy_init_buffer( b, file );
  1898. X
  1899. X    return ( b );
  1900. X    }
  1901. X
  1902. X
  1903. X#ifdef YY_USE_PROTOS
  1904. Xvoid yy_delete_buffer( YY_BUFFER_STATE b )
  1905. X#else
  1906. Xvoid yy_delete_buffer( b )
  1907. XYY_BUFFER_STATE b;
  1908. X#endif
  1909. X
  1910. X    {
  1911. X    if ( b == yy_current_buffer )
  1912. X    yy_current_buffer = (YY_BUFFER_STATE) 0;
  1913. X
  1914. X    free( (char *) b->yy_ch_buf );
  1915. X    free( (char *) b );
  1916. X    }
  1917. X
  1918. X
  1919. X#ifdef YY_USE_PROTOS
  1920. Xvoid yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
  1921. X#else
  1922. Xvoid yy_init_buffer( b, file )
  1923. XYY_BUFFER_STATE b;
  1924. XFILE *file;
  1925. X#endif
  1926. X
  1927. X    {
  1928. X    b->yy_input_file = file;
  1929. X
  1930. X    /* we put in the '\n' and start reading from [1] so that an
  1931. X     * initial match-at-newline will be true.
  1932. X     */
  1933. X
  1934. X    b->yy_ch_buf[0] = '\n';
  1935. X    b->yy_n_chars = 1;
  1936. X
  1937. X    /* we always need two end-of-buffer characters.  The first causes
  1938. X     * a transition to the end-of-buffer state.  The second causes
  1939. X     * a jam in that state.
  1940. X     */
  1941. X    b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
  1942. X    b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR;
  1943. X
  1944. X    b->yy_buf_pos = &b->yy_ch_buf[1];
  1945. X
  1946. X    b->yy_eof_status = EOF_NOT_SEEN;
  1947. X    }
  1948. END_OF_FILE
  1949.   if test 19796 -ne `wc -c <'flex.skel'`; then
  1950.     echo shar: \"'flex.skel'\" unpacked with wrong size!
  1951.   fi
  1952.   # end of 'flex.skel'
  1953. fi
  1954. if test -f 'yylex.c' -a "${1}" != "-c" ; then 
  1955.   echo shar: Will not clobber existing file \"'yylex.c'\"
  1956. else
  1957.   echo shar: Extracting \"'yylex.c'\" \(4244 characters\)
  1958.   sed "s/^X//" >'yylex.c' <<'END_OF_FILE'
  1959. X/* yylex - scanner front-end for flex */
  1960. X
  1961. X/*-
  1962. X * Copyright (c) 1990 The Regents of the University of California.
  1963. X * All rights reserved.
  1964. X *
  1965. X * This code is derived from software contributed to Berkeley by
  1966. X * Vern Paxson.
  1967. X * 
  1968. X * The United States Government has rights in this work pursuant
  1969. X * to contract no. DE-AC03-76SF00098 between the United States
  1970. X * Department of Energy and the University of California.
  1971. X *
  1972. X * Redistribution and use in source and binary forms are permitted provided
  1973. X * that: (1) source distributions retain this entire copyright notice and
  1974. X * comment, and (2) distributions including binaries display the following
  1975. X * acknowledgement:  ``This product includes software developed by the
  1976. X * University of California, Berkeley and its contributors'' in the
  1977. X * documentation or other materials provided with the distribution and in
  1978. X * all advertising materials mentioning features or use of this software.
  1979. X * Neither the name of the University nor the names of its contributors may
  1980. X * be used to endorse or promote products derived from this software without
  1981. X * specific prior written permission.
  1982. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  1983. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  1984. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1985. X */
  1986. X
  1987. X#ifndef lint
  1988. Xstatic char rcsid[] =
  1989. X    "@(#) $Header: /usr/fsys/odin/a/vern/flex/RCS/yylex.c,v 2.5 90/06/27 23:48:40 vern Exp $ (LBL)";
  1990. X#endif
  1991. X
  1992. X#include <ctype.h>
  1993. X#include "flexdef.h"
  1994. X#include "parse.h"
  1995. X
  1996. X
  1997. X/* ANSI C does not guarantee that isascii() is defined */
  1998. X#ifndef isascii
  1999. X#define isascii(c) ((c) <= 0177)
  2000. X#endif
  2001. X
  2002. X
  2003. X/* yylex - scan for a regular expression token
  2004. X *
  2005. X * synopsis
  2006. X *
  2007. X *   token = yylex();
  2008. X *
  2009. X *     token - return token found
  2010. X */
  2011. X
  2012. Xint yylex()
  2013. X
  2014. X    {
  2015. X    int toktype;
  2016. X    static int beglin = false;
  2017. X
  2018. X    if ( eofseen )
  2019. X    toktype = EOF;
  2020. X    else
  2021. X    toktype = flexscan();
  2022. X
  2023. X    if ( toktype == EOF || toktype == 0 )
  2024. X    {
  2025. X    eofseen = 1;
  2026. X
  2027. X    if ( sectnum == 1 )
  2028. X        {
  2029. X        synerr( "premature EOF" );
  2030. X        sectnum = 2;
  2031. X        toktype = SECTEND;
  2032. X        }
  2033. X
  2034. X    else if ( sectnum == 2 )
  2035. X        {
  2036. X        sectnum = 3;
  2037. X        toktype = 0;
  2038. X        }
  2039. X
  2040. X    else
  2041. X        toktype = 0;
  2042. X    }
  2043. X
  2044. X    if ( trace )
  2045. X    {
  2046. X    if ( beglin )
  2047. X        {
  2048. X        fprintf( stderr, "%d\t", num_rules + 1 );
  2049. X        beglin = 0;
  2050. X        }
  2051. X
  2052. X    switch ( toktype )
  2053. X        {
  2054. X        case '<':
  2055. X        case '>':
  2056. X        case '^':
  2057. X        case '$':
  2058. X        case '"':
  2059. X        case '[':
  2060. X        case ']':
  2061. X        case '{':
  2062. X        case '}':
  2063. X        case '|':
  2064. X        case '(':
  2065. X        case ')':
  2066. X        case '-':
  2067. X        case '/':
  2068. X        case '\\':
  2069. X        case '?':
  2070. X        case '.':
  2071. X        case '*':
  2072. X        case '+':
  2073. X        case ',':
  2074. X        (void) putc( toktype, stderr );
  2075. X        break;
  2076. X
  2077. X        case '\n':
  2078. X        (void) putc( '\n', stderr );
  2079. X
  2080. X        if ( sectnum == 2 )
  2081. X            beglin = 1;
  2082. X
  2083. X        break;
  2084. X
  2085. X        case SCDECL:
  2086. X        fputs( "%s", stderr );
  2087. X        break;
  2088. X
  2089. X        case XSCDECL:
  2090. X        fputs( "%x", stderr );
  2091. X        break;
  2092. X
  2093. X        case WHITESPACE:
  2094. X        (void) putc( ' ', stderr );
  2095. X        break;
  2096. X
  2097. X        case SECTEND:
  2098. X        fputs( "%%\n", stderr );
  2099. X
  2100. X        /* we set beglin to be true so we'll start
  2101. X         * writing out numbers as we echo rules.  flexscan() has
  2102. X         * already assigned sectnum
  2103. X         */
  2104. X
  2105. X        if ( sectnum == 2 )
  2106. X            beglin = 1;
  2107. X
  2108. X        break;
  2109. X
  2110. X        case NAME:
  2111. X        fprintf( stderr, "'%s'", nmstr );
  2112. X        break;
  2113. X
  2114. X        case CHAR:
  2115. X        switch ( yylval )
  2116. X            {
  2117. X            case '<':
  2118. X            case '>':
  2119. X            case '^':
  2120. X            case '$':
  2121. X            case '"':
  2122. X            case '[':
  2123. X            case ']':
  2124. X            case '{':
  2125. X            case '}':
  2126. X            case '|':
  2127. X            case '(':
  2128. X            case ')':
  2129. X            case '-':
  2130. X            case '/':
  2131. X            case '\\':
  2132. X            case '?':
  2133. X            case '.':
  2134. X            case '*':
  2135. X            case '+':
  2136. X            case ',':
  2137. X            fprintf( stderr, "\\%c", yylval );
  2138. X            break;
  2139. X
  2140. X            default:
  2141. X            if ( ! isascii( yylval ) || ! isprint( yylval ) )
  2142. X                fprintf( stderr, "\\%.3o", yylval );
  2143. X            else
  2144. X                (void) putc( yylval, stderr );
  2145. X            break;
  2146. X            }
  2147. X            
  2148. X        break;
  2149. X
  2150. X        case NUMBER:
  2151. X        fprintf( stderr, "%d", yylval );
  2152. X        break;
  2153. X
  2154. X        case PREVCCL:
  2155. X        fprintf( stderr, "[%d]", yylval );
  2156. X        break;
  2157. X
  2158. X        case EOF_OP:
  2159. X        fprintf( stderr, "<<EOF>>" );
  2160. X        break;
  2161. X
  2162. X        case 0:
  2163. X        fprintf( stderr, "End Marker" );
  2164. X        break;
  2165. X
  2166. X        default:
  2167. X        fprintf( stderr, "*Something Weird* - tok: %d val: %d\n",
  2168. X             toktype, yylval );
  2169. X        break;
  2170. X        }
  2171. X    }
  2172. X        
  2173. X    return ( toktype );
  2174. X    }
  2175. END_OF_FILE
  2176.   if test 4244 -ne `wc -c <'yylex.c'`; then
  2177.     echo shar: \"'yylex.c'\" unpacked with wrong size!
  2178.   fi
  2179.   # end of 'yylex.c'
  2180. fi
  2181. echo shar: End of archive 6 \(of 10\).
  2182. cp /dev/null ark6isdone
  2183. MISSING=""
  2184. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  2185.     if test ! -f ark${I}isdone ; then
  2186.     MISSING="${MISSING} ${I}"
  2187.     fi
  2188. done
  2189. if test "${MISSING}" = "" ; then
  2190.     echo You have unpacked all 10 archives.
  2191.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2192. else
  2193.     echo You still must unpack the following archives:
  2194.     echo "        " ${MISSING}
  2195. fi
  2196. exit 0
  2197. exit 0 # Just in case...
  2198.